﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SAUlot
{
    public partial class AirplaneMainView : Form
    {
        private bool thread_started;

        private AirplaneControler airplaneControler;
        public AirplaneControler Controler
        {
            get { return airplaneControler; }
            set { airplaneControler = value; }
        }

        private RaportForm raportForm;
        public AirplaneMainView()
        {
            InitializeComponent();
            raportForm = new RaportForm();
            raportForm.Hide();
            thread_started = false;
        }

        public Size ViewportSize
        {
            get { return canvas.Size; }
        }

        public IntPtr CanvasHandle
        {
            get { return canvas.Handle; }
        }


        public void WriteToRaport(string text)
        {
            raportForm.addMessage(text);
        }

        private void raportButton_Click(object sender, EventArgs e)
        {
            raportForm.Show();
        }

        private void startStopButton_Click(object sender, EventArgs e)
        {
            if (!thread_started)
            {
                startStopButton.Text = "Stop";
                thread_started = true;
                airplaneControler.StartThread();
            }
            else
            {
                startStopButton.Text = "Start";
                airplaneControler.EndThread();
                thread_started = false;
            }
        }
        
        private void AirplaneMainView_FormClosing(object sender, FormClosedEventArgs e)
        {
            airplaneControler.EndThread();
            Application.Exit();
        }

        private void resetButton_Click(object sender, EventArgs e)
        {
            if (thread_started)
            {
                thread_started = false;
                airplaneControler.EndThread();
                startStopButton.Text = "Start";
            }
            airplaneControler.Reset();

         }
   }
}

